package handler

import (
	"2302a/testyuekao/api/resp"
	"fmt"
	"github.com/gin-gonic/gin"
	"path"
	"time"
)

func FileUpload(c *gin.Context) {
	file, _ := c.FormFile("file")

	ext := path.Ext(file.Filename)
	if ext != ".png" && ext != ".jpg" && ext != ".mp4" {
		resp.Error(c, 10000, "上传文件限制格式为.mp4", nil)
		return
	}
	if file.Size > 1024*1024*200 {
		resp.Error(c, 10000, "上传文件大小不能超过 200MB", nil)
		return
	}
	upload := time.Now().Format("20060102150405") + file.Filename
	dst := "D:\\phpstudy_pro\\WWW\\" + upload
	c.SaveUploadedFile(file, dst)
	resp.Success(c, "上传文件成功", fmt.Sprintf("http://localhost/%s", upload))
}
